#ifndef UTILITY_H
#define UTILITY_H

#include <string>
#include <set>
#include <vector>
#include <unordered_map>
#include <sqlite3.h> 
using namespace std;

#define KEYWORD_THRESHOLD 10 // if the keyword only appear number of times which is below this threshold, then it will not consider

// string utilities
bool IsStringContainNonAsciiChar(string& s);
string ReplaceStrangeCharacterWithSpace(string& s);

// check whether the token is a keyword
bool IsTokenKeyword(string& token, set<string>& stop_word_set);
bool IsTokenAllDigit(string& token);

// load weighted adjacency list
void LoadAdjGraph(vector<vector<pair<int,int> > >& adj_lists, string in_dir);

// load partition information, return number of unique partitions
int LoadGraphPartition(
	unordered_map<int,int>& node_partition_map,	// user to partition map
	string in_dir, int num_partition);

// load nearest 2 hop neighbour for each node
void Load2HopNN(vector<int>& nn2hop, string in_dir);

// load partition distance and pivot nodes information
void LoadPartitionDistAndPivots(
	vector<vector<int> >& partition_dist,		// distance matrix between partitions
	vector<int>& pivot_nodes,					// index of pivot nodes
	vector<vector<int> >& pivot_to_all_dist,	// distance between a partition's pivot to all points
	string in_dir, int num_nodes, int num_partition);

// load keyword name and the keyword idf
void LoadKeyword(
	unordered_map<string,int>& keyword_map,		// map between keyword string to the keyword index
	vector<double>& keyword_idf,					// each entry denotes how many documents contain this keyword
	string in_dir);

// to handle sql statements
void SQLerror(int rc, char* zErrMsg, bool print=false);

// compare operators
template <class T1, class T2>
struct pair_greater{
	bool operator() (const pair<T1,T2>& x, const pair<T1,T2>& y) const {return x.first>y.first;}
};

// compare operators
template <class T1, class T2>
struct pair_smaller{
	bool operator() (const pair<T1,T2>& x, const pair<T1,T2>& y) const {return x.first<y.first;}
};

template <class T1, class T2>
struct pair_second_greater{
	bool operator() (const pair<T1,T2>& x, const pair<T1,T2>& y) const {return x.second > y.second;}
};

#endif